package weeny.recycle;

import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;

import prefuse.Display;
import prefuse.controls.DragControl;
import prefuse.visual.VisualItem;

@Deprecated
public class DragInRectController extends DragControl {
	public static class Handler{
		public void afterItemPressed(VisualItem item){}
		public void afterItemRelease(VisualItem item){}
		public void afterItemDragged(VisualItem item){}
	}
	
	private Rectangle2D rect = null;
	public DragInRectController(Rectangle2D rect){
		this.rect = rect;
	}
	@Override
	public void itemEntered(VisualItem item, MouseEvent e) {
		super.itemEntered(item, e);
	}
	@Override
	public void itemExited(VisualItem item, MouseEvent e) {
		super.itemExited(item, e);
	}
	@Override
	public void itemPressed(VisualItem item, MouseEvent e) {
		super.itemPressed(item, e);
	}
	@Override
	public void itemReleased(VisualItem item, MouseEvent e) {
		super.itemReleased(item, e);
	}
	@Override
	public void itemDragged(VisualItem item, MouseEvent e) {
        dragged = true;
        Display d = (Display)e.getComponent();
        d.getAbsoluteCoordinate(e.getPoint(), temp);
        double dx = temp.getX()-down.getX();
        double dy = temp.getY()-down.getY();
        double x = item.getX();
        double y = item.getY();

        item.setStartX(x);  item.setStartY(y);
        if (x+dx > rect.getMaxX()+1 || x+dx < rect.getMinX()-1) {
        	//out of rectangle
		}
        else{
        	item.setX(x+dx);    
        	item.setEndX(x+dx); 
        }
        if (y+dy > rect.getMaxY()+1 || y+dy < rect.getMinY()-1) {
			//out of rectangle
		}
        else{
        	item.setY(y+dy);
        	item.setEndY(y+dy);
        }
        
        if ( repaint )
            item.getVisualization().repaint();
        
        down.setLocation(temp);
        if ( action != null )
            d.getVisualization().run(action);
	}
}
